// view/index/bossxq/bossxq.js
let app = getApp()
let yuming = app.globalData.yuming
var lastFrameTime = 0;
var count = 0;
var ctx = null;
var factor = {
  speed: .008, // 运动速度，值越小越慢
  t: 0 //  贝塞尔函数系数
};
var that;
var timer = null; // 循环定时器
var shuzong = []
var shu = []
Page({
  /**
   * 页面的初始数据
   */
  data: {
    buttonClicked: false,
    yuming: yuming,
    heights: "",
    title: '老板圈',
    weidian: false,
    focusInput: false,
    height: 0,
    isInput: false,
    wen: '',
    pl: [], //该详情的评论列表
    pls: [],
    id: '', //id
    ids: '', //回复谁的id
    pae: 1,
    total: '', //评论数
    fid: '', //0评论 1回复
    fbnr: '', //获取发布内容
    shopId: wx.getStorageSync('shopId'),
    page: 1
  },
  // 详情
  xq() {
    // wx.showLoading({
    //   title: '加载中',
    //   icon:'none',
    // })
    var that = this
    wx.request({
      url: yuming + 'shop/shopFindBossCircle',
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token: wx.getStorageSync('token')
      },
      data: {
        shopId: wx.getStorageSync('shopId'),
        id: that.data.id
      },
      success: function (res) {
        wx.hideLoading({})
        that.setData({
          xiao: res.data.data
        })
        that.plxq()
      },
      fail: function () {
        app.consoleLog("请求数据失败");
      }
    })
  },
  // 点赞
  dianzan(e) {
    var id = e.currentTarget.dataset.id
    console.log(id)
    var that = this
    wx.request({
      url: yuming + 'shop/shopPubBossCircle',
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token: wx.getStorageSync('token')
      },
      data: {
        shopId: wx.getStorageSync('shopId'),
        id: id
      },
      success: function (res) {
        // wx.showToast({
        //   title: res.data.msg,
        //   icon:'none'
        // })
        // setTimeout(function(){

        if (res.data.code == 200) {
          that.xq()
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
        // },1000)
      },
      fail: function () {
        app.consoleLog("请求数据失败");
      }
    })
  },
  // 点赞
  dianzans(e) {
    var id = e.currentTarget.dataset.id
    console.log(id)
    var that = this
    wx.request({
      url: yuming + 'shop/shopPubBossCment',
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token: wx.getStorageSync('token')
      },
      data: {
        shopId: wx.getStorageSync('shopId'),
        id: id
      },
      success: function (res) {
        // wx.showToast({
        //   title: res.data.msg,
        //   icon:'none'
        // })
        // setTimeout(function(){
        that.xq()
        // },1000)
      },
      fail: function () {
        app.consoleLog("请求数据失败");
      }
    })
  },
  // 关注
  yiguan(e) {
    var id = e.currentTarget.dataset.id
    var that = this
    console.log(e)
    wx.request({
      url: yuming + 'shop/shopAddBossfollow',
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token: wx.getStorageSync('token')
      },
      data: {
        shopId: wx.getStorageSync('shopId'),
        fid: id
      },
      success: function (res) {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
        that.xq()
      },
      fail: function () {
        app.consoleLog("请求数据失败");
      }
    })
  },
  // 查看更多
  lookmore() {
    shuzong = this.data.pl
    this.setData({
      page: (this.data.page) + 1
    })
    this.plxq()
  },
  // 评论详情
  plxq() {
    var that = this
    wx.request({
      url: yuming + 'shop/shopSelectBossCment',
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token: wx.getStorageSync('token')
      },
      data: {
        shopId: wx.getStorageSync('shopId'),
        id: that.data.id,
        page: that.data.page
      },
      success: function (res) {
        shu = res.data.data
        if (that.data.page != 1) {
          if (shu.length == 0) {
            wx.showToast({
              title: '没有更多数据了~',
              icon: "none"
            })
            that.setData({
              pl: []
            })
          }
        }
        that.setData({
          pl: shuzong.concat(shu),
          total: res.data.total
        })
      },
      fail: function () {
        app.consoleLog("请求数据失败");
      }
    })
  },
  inputFocus(e) {
    console.log(e)
    this.setData({
      height: e.detail.height
    })
    var that = this
    // setTimeout(function() {
    that.setData({
      isInput: true
    })
    // },1000)
  },
  inputBlur(e) {
    this.setData({
      isInput: false,
    })
  },
  // 评论
  focusButn: function (e) {
    var fid = e.currentTarget.dataset.fid
    this.setData({
      focusInput: true,
      isInput: true,
      fbnr: '',
      fid: fid,
    })
  },
  // 回复
  huifu(e) {
    var fid = e.currentTarget.dataset.fid
    this.setData({
      focusInput: true,
      isInput: true,
      fbnr: '',
      fid: fid,
    })
  },
  // 放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    var list = e.currentTarget.dataset.list
    var arr = []
    for (let i in list) {
      arr.push(list[i]); //属性
    }
    wx.previewImage({
      current: img,
      urls: arr
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  fbnr(e) {
    this.setData({
      fbnr: e.detail.value
    })
  },
  // 发送
  fasong() {
    var bcId = ''
    var that = this
    that.setData({
      buttonClicked: true
    })
    wx.request({
      url: yuming + 'shop/shopAddBossCment',
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token: wx.getStorageSync('token')
      },
      data: {
        shopId: wx.getStorageSync('shopId'),
        fid: that.data.fid,
        bcId: that.data.id,
        bcCment: that.data.fbnr
      },
      success: function (res) {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
        if (res.data.code == 200) {
          that.setData({
            isInput: false,
            fbnr: ''
          })
          setTimeout(function () {
            that.xq()
          }, 1000)
        } else {
          that.setData({
            buttonClicked: false
          })
        }

      },
      fail: function () {
        app.consoleLog("请求数据失败");
      }
    })
  },
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      id: options.id
    })
    that = this
    //获取canvas实例
    ctx = wx.createCanvasContext('mycanvas')
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.xq()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    if (timer != null) {
      clearTimeout(timer)
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})